#pragma once
#include "EXEdit.h"
#include "EXSpinButtonCtrlResSet.h"
// CEXSpinButtonCtrl

class AFX_EXT_CLASS CEXSpinButtonCtrl : public CSpinButtonCtrl
{
	DECLARE_DYNAMIC(CEXSpinButtonCtrl)

public:
  enum SPIN_STYLE
  {
    NOIMAGE,
    SPIN_CTRL = 19,
  };

	CEXSpinButtonCtrl();
	virtual ~CEXSpinButtonCtrl();

	BOOL SetBitmaps(UINT nBkgndID, UINT nUpLeftID, UINT nDownRightID, int nCount, 
                  COLORREF crBkgnd, int nTopHeight=0, int nBottomHeight=0, 
                  int nLeftWidth=0, int nRightWidth=0);

	BOOL SetUpLeftBitmaps(UINT nBkgndID, UINT nUpLeftID, int nCount, 
                        COLORREF crBkgnd, int nTopHeight=0, int nBottomHeight=0, 
                        int nLeftWidth=0, int nRightWidth=0);

	BOOL SetDownRightBitmaps(UINT nBkgndID, UINT nDownRightID, int nCount, 
                          COLORREF crBkgnd, int nTopHeight=0, 
                          int nBottomHeight=0, int nLeftWidth=0, 
                          int nRightWidth=0);

	void SetBkgndBitmap(UINT nBkgndID, COLORREF crBkgnd);


  void SetResSet(CEXBaseResSet* pResSet);
  CEXSpinButtonCtrlResSet* m_pSpinResSet;
  void SetBuddyEdit(CEXEdit* EditBox);

protected:
	BOOL InitBgBitmap(CBitmap & src, CBitmap & bmpBtn, CBitmap & dist, int index, 
                    int count, BOOL bUp, int nTopHeight=0, int nBottomHeight=0, 
                    int nLeftWidth=0, int nRightWidth=0, int nExtra = 0);

	void DrawUpLeftFrame(CDC * pDC);
	void DrawDownRightFrame(CDC * pDC);

	enum { IDT_MOUSE_LEAVE = 111, IDT_MOUSE_LEAVE_TIME = 20 };

	enum STATUS
	{
		normal,
		focus,
		select,
		disable
	};

	BOOL m_bTimerSet;
	BOOL m_bHorizontal;

	BOOL m_bSetUpLeftBitmap;
	BOOL m_bSetDownRightBitmap;

	int m_nUpLeftTopHeight;
	int m_nUpLeftBottomHeight;
	int m_nUpLeftLeftWidth;
	int m_nUpLeftRightWidth;

	int m_nDownRightTopHeight;
	int m_nDownRightBottomHeight;
	int m_nDownRightLeftWidth;
	int m_nDownRightRightWidth;

	UINT m_nUpLeftBkgndID;
	UINT m_nDownRightBkgndID;

	UINT m_nUpLeftID;
	UINT m_nDownRightID;

	int m_nNumOfBgPics;
	COLORREF m_crTransparent;
	COLORREF m_crBkgnd;

	CBitmap m_bmpUpLeft;
	CBitmap m_bmpDownRight;

	CRect m_rcUpLeft;
	CRect m_rcDownRight;

	BOOL m_bUpLeftFocus;
	BOOL m_bDownRightFocus;

	BOOL m_bUpLeftSelect;
	BOOL m_bDownRightSelect;

	UINT m_nBkgndID;
	CBitmap m_bmpBkgnd;

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
protected:
	virtual void PreSubclassWindow();
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
public:
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg LRESULT OnMouseLeaveNotify(WPARAM w, LPARAM l);
};


